import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` 将不显示在侧边栏（默认为false）
* alwaysShow: true               如果设置为true，将始终显示根菜单，无论其子路径长度
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     将控制页面角色（可以设置多个角色）
    title: 'title'                在子菜单和面包屑中显示的名称（推荐集）
    icon: 'svg-name'              图标显示在边栏中，如果为真，则页面将不会被缓存（默认为false）
    noCache: true                 图标显示在边栏中，如果为真，则页面将不会被缓存（默认为false）
  }
**/

export const constantRouterMap = [{
  path: '/redirect',
  component: Layout,
  hidden: true,
  children: [{
    path: '/redirect/:path*',
    component: () =>
                import('@/views/redirect/index')
  }]
},
{
  path: '/login',
  component: () =>
            import('@/views/login/index'),
  hidden: true
},
{
  path: '/auth-redirect',
  component: () =>
            import('@/views/login/authredirect'),
  hidden: true
},
{
  path: '/404',
  component: () =>
            import('@/views/errorPage/404'),
  hidden: true
},
{
  path: '/401',
  component: () =>
            import('@/views/errorPage/401'),
  hidden: true
},
{
  path: '',
  component: Layout,
  redirect: 'dashboard',
  children: [{
    path: 'dashboard',
    component: () =>
                import('@/views/dashboard/index'),
    name: 'Dashboard',
    meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
  }]
}
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [{
  path: '/permission',
  component: Layout,
  redirect: '/permission/index',
  alwaysShow: true, // will always show the root menu
  meta: {
    title: 'permission',
    icon: 'lock',
    roles: ['admin', 'editor'] // you can set roles in root nav
  },
  children: [{
    path: 'page',
    component: () =>
                import('@/views/permission/page'),
    name: 'PagePermission',
    meta: {
      title: 'pagePermission',
      roles: ['admin'] // or you can only set roles in sub nav
    }
  }]
},
{
  path: '/admin',
  component: Layout,
  redirect: '/admin/index',
  alwaysShow: true, // will always show the root menu
  meta: {
    title: 'admin',
    icon: 'user',
    roles: ['admin'] // you can set roles in root nav
  },
  children: [{
    path: 'list',
    component: () =>
                import('@/views/admin/list'),
    name: 'adminList',
    meta: {
      title: 'adminList',
      roles: ['admin'] // or you can only set roles in sub nav
    }
  }, {
    path: 'role',
    component: () =>
                import('@/views/admin/role'),
    name: 'adminRole',
    meta: {
      title: 'adminRole',
      roles: ['admin'] // or you can only set roles in sub nav
    }
  }]
}, {
  path: '/uiJson',
  component: Layout,
  redirect: '/uiJson/form',
  alwaysShow: true, // will always show the root menu
  meta: {
    title: 'uiJson',
    icon: 'user'
  },
  children: [{
    path: 'form',
    component: () =>
                import('@/views/jsonApi/index'),
    name: 'uiJsonForm',
    meta: {
      title: 'From表单'
    }
  }]
}, { path: '*', redirect: '/404', hidden: true }
]
